package com.aef.service;

import java.util.List;

import com.aef.model.TdFeedback;
import com.aef.model.TdRecycle;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

public class RecycleService {
	/**
	 *判断openid时候绑定
	 * @param openid
	 * @return
	 */
	public List<Record> JudgeOpenidbund(String openid){
		List<Record> list;
		if(openid==""){
			list = Db.find("select * from td_company r where r.openid !=?" ,openid);	
		}else{
			list = Db.find("select * from td_company r where r.openid =?" ,openid);	
		}
		return list;  
	}
	/**
	 * 发起收油
	 * @param recycle
	 * @return 
	 */
	public boolean recycle(TdRecycle recycle){
		boolean recycletype=recycle.save();
		return recycletype;
	}
	/**
	 * 分页
	 * @param pageNumber
	 * @param pageSize
	 * @param name
	 * @return
	 */
	public Page<Record> paginate(int pageNumber, int pageSize,String name,String tablename) {
		return Db.paginate(pageNumber, pageSize, "select *", "from "+tablename+" where company_name LIKE ? AND openid=''","%"+name+"%");
	}
	/**
	 * 公司绑定
	 * @param comp_openid
	 * @param id
	 * @return
	 */
	public int UpdateCompany(String comp_openid, int id){
		int record=Db.update("update td_company  set openid=? where id=?",comp_openid,id);
		return record;
	}
	/**
	 * 获取收油记录
	 * @param openid
	 * @return
	 */
	public List<Record> getrecord(String companyid){
		List<Record> list = Db.find("select * from td_recycle r where r.companyid =?" ,companyid);
		return list;  
	}
	/**
	 * 获取订单详细信息
	 * @param companyid
	 * @return
	 */
	public List<Record> getrecordandcompany(String recoedid){
		List<Record> list = Db.find("select *  from td_recycle , td_company where td_recycle.companyid = td_company.id AND td_recycle.id=?" ,recoedid);
		return list;  
	}
	/**
	 * 反馈意见
	 * @param feedback
	 * @return 
	 */
	public boolean Savefeedback(TdFeedback feedback){
		boolean feedbacktype=feedback.save();
		return feedbacktype;
	}
}
